package PTA;
import java.util.Scanner;

public class test_2 {
    public static String sub(String buf,int start,int end) {
        return new StringBuffer(buf).substring(start, end).toString();
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        //StringBuilder[] sb = new StringBuilder[n];
        String[] buf = new String[n];
        for(int i = 0;i < n;i++) {
            buf[i] = scan.next();
        }

        for (int i = 0; i < n; i++) {
            int k1 = Integer.parseInt(sub(buf[i],6,10));
            for (int j = 0; j < n - 1; j++) {
                int k2 = Integer.parseInt(sub(buf[j],6,10));
                if(k2 > k1) {
                    String tmp = buf[i];
                    buf[i] = buf[j];
                    buf[j] = tmp;
                }
            }
        }

        for(String b:buf) {
            System.out.println(sub(b,6,10)+"-"
                    +sub(b,10,12)+"-"
                    +sub(b,12,14));
        }

    }
}